
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class LinkUserAddressComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public LinkUserAddressComponent()
        {

        }
		
		/// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public LinkUserAddress SelectOne(int UserAddressId)
        {  
			PlacementManager.DAL.LinkUserAddress_DAL o = new PlacementManager.DAL.LinkUserAddress_DAL();
			o.UserAddressId = UserAddressId;
			DataTable dt = o.SelectOne().Tables[0];
			
			if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
				PlacementManager.LinkUserAddress LinkUserAddressToReturn = new PlacementManager.LinkUserAddress((int)row["UserAddressId"], (int)row["UserId"], (int)row["AddressId"], (bool)row["IsCurrent"], (bool)row["IsPrimary"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]);
				return LinkUserAddressToReturn;
			}
			else
			{
				PlacementManager.LinkUserAddress LinkUserAddressToReturnEmpty = new PlacementManager.LinkUserAddress();
                return LinkUserAddressToReturnEmpty;
			}
        }
		
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkUserAddress> SelectAll(string sortExpression)
        {
            List<LinkUserAddress> listLinkUserAddress = new List<LinkUserAddress>();
            PlacementManager.DAL.LinkUserAddress_DAL o = new PlacementManager.DAL.LinkUserAddress_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listLinkUserAddress.Add(new LinkUserAddress((int)row["UserAddressId"], (int)row["UserId"], (int)row["AddressId"], (bool)row["IsCurrent"], (bool)row["IsPrimary"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listLinkUserAddress.Sort(new LinkUserAddressComparer(sortExpression));
            return listLinkUserAddress;
        }
	
		/// <summary>
        /// Selects all records from the database table based on a foreign key.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkUserAddress> SelectAllWAddressId(int AddressId, string sortExpression)
		{
			List<LinkUserAddress> listLinkUserAddress = new List<LinkUserAddress>();
			PlacementManager.DAL.LinkUserAddress_DAL o = new PlacementManager.DAL.LinkUserAddress_DAL();
			o.AddressId = AddressId;
			DataSet ds = o.SelectAllWAddressId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listLinkUserAddress.Add(new LinkUserAddress((int)row["UserAddressId"], (int)row["UserId"], (int)row["AddressId"], (bool)row["IsCurrent"], (bool)row["IsPrimary"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listLinkUserAddress.Sort(new LinkUserAddressComparer(sortExpression));
			return listLinkUserAddress;
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<LinkUserAddress> SelectAllWUserId(int UserId, string sortExpression)
		{
			List<LinkUserAddress> listLinkUserAddress = new List<LinkUserAddress>();
			PlacementManager.DAL.LinkUserAddress_DAL o = new PlacementManager.DAL.LinkUserAddress_DAL();
			o.UserId = UserId;
			DataSet ds = o.SelectAllWUserId();
			foreach (DataRow row in ds.Tables[0].Rows)
			{
				listLinkUserAddress.Add(new LinkUserAddress((int)row["UserAddressId"], (int)row["UserId"], (int)row["AddressId"], (bool)row["IsCurrent"], (bool)row["IsPrimary"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));			
			}
			if (sortExpression == string.Empty)
			{
				sortExpression = "DateCreated desc";
			}
			listLinkUserAddress.Sort(new LinkUserAddressComparer(sortExpression));
			return listLinkUserAddress;
		}


		/// <summary>
        /// Inserts a new row into the datatable.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(LinkUserAddress o)
        {	
            PlacementManager.DAL.LinkUserAddress_DAL oLinkUserAddress = new PlacementManager.DAL.LinkUserAddress_DAL();
			oLinkUserAddress.UserId = o.UserId;
			oLinkUserAddress.AddressId = o.AddressId;
			oLinkUserAddress.IsCurrent = o.IsCurrent;
			oLinkUserAddress.IsPrimary = o.IsPrimary;
			oLinkUserAddress.IsActive = o.IsActive;
			oLinkUserAddress.DateCreated = o.DateCreated;
			oLinkUserAddress.CreatedBy = o.CreatedBy;
			oLinkUserAddress.DateUpdated = o.DateUpdated;
			oLinkUserAddress.UpdatedBy = o.UpdatedBy;

            return oLinkUserAddress.Insert();
        }
		
		/// <summary>
        /// Inserts a new row into the datatable by passing parameters represneting each column.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Insert, true)]
		public int Insert(int UserId, int AddressId, bool IsCurrent, bool IsPrimary, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.LinkUserAddress_DAL oLinkUserAddress = new PlacementManager.DAL.LinkUserAddress_DAL();

			oLinkUserAddress.UserId = UserId;
			oLinkUserAddress.AddressId = AddressId;
			oLinkUserAddress.IsCurrent = IsCurrent;
			oLinkUserAddress.IsPrimary = IsPrimary;
			oLinkUserAddress.IsActive = IsActive;
			oLinkUserAddress.DateCreated = DateCreated;
			oLinkUserAddress.CreatedBy = CreatedBy;
			oLinkUserAddress.DateUpdated = DateUpdated;
			oLinkUserAddress.UpdatedBy = UpdatedBy;

            return oLinkUserAddress.Insert();
        }

		/// <summary>
        /// Updates a row in the database table based on the primary key.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(LinkUserAddress o)
        {	
            PlacementManager.DAL.LinkUserAddress_DAL oLinkUserAddress = new PlacementManager.DAL.LinkUserAddress_DAL();
			oLinkUserAddress.UserAddressId = o.UserAddressId;
			oLinkUserAddress.UserId = o.UserId;
			oLinkUserAddress.AddressId = o.AddressId;
			oLinkUserAddress.IsCurrent = o.IsCurrent;
			oLinkUserAddress.IsPrimary = o.IsPrimary;
			oLinkUserAddress.IsActive = o.IsActive;
			oLinkUserAddress.DateCreated = o.DateCreated;
			oLinkUserAddress.CreatedBy = o.CreatedBy;
			oLinkUserAddress.DateUpdated = o.DateUpdated;
			oLinkUserAddress.UpdatedBy = o.UpdatedBy;

            return oLinkUserAddress.Update();
        }
		
		/// <summary>
        /// Updates a row in the database table based on the primary key by passing the values of each column as parameters.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Update, true)]
		public bool Update(int UserAddressId, int UserId, int AddressId, bool IsCurrent, bool IsPrimary, bool IsActive, DateTime DateCreated, string CreatedBy, DateTime DateUpdated, string UpdatedBy)
        {
            PlacementManager.DAL.LinkUserAddress_DAL oLinkUserAddress = new PlacementManager.DAL.LinkUserAddress_DAL();

			oLinkUserAddress.UserAddressId = UserAddressId;
			oLinkUserAddress.UserId = UserId;
			oLinkUserAddress.AddressId = AddressId;
			oLinkUserAddress.IsCurrent = IsCurrent;
			oLinkUserAddress.IsPrimary = IsPrimary;
			oLinkUserAddress.IsActive = IsActive;
			oLinkUserAddress.DateCreated = DateCreated;
			oLinkUserAddress.CreatedBy = CreatedBy;
			oLinkUserAddress.DateUpdated = DateUpdated;
			oLinkUserAddress.UpdatedBy = UpdatedBy;

            return oLinkUserAddress.Update();
        }
		
		/// <summary>
        /// Deletes one row in the database table.
        /// </summary>
        /// <param name="o">An object of a datatype representing a row in the database table.</param>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(LinkUserAddress o)
        {
            PlacementManager.DAL.LinkUserAddress_DAL oLinkUserAddress_DAL = new PlacementManager.DAL.LinkUserAddress_DAL();
            oLinkUserAddress_DAL.UserAddressId = o.UserAddressId;
            return oLinkUserAddress_DAL.Delete();
        }
		
		/// <summary>
        /// Deletes one row in the database table by passing the primary key.
        /// </summary>
        /// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool Delete(int UserAddressId)
        {
            PlacementManager.DAL.LinkUserAddress_DAL oLinkUserAddress_DAL = new PlacementManager.DAL.LinkUserAddress_DAL();
            oLinkUserAddress_DAL.UserAddressId = UserAddressId;
            return oLinkUserAddress_DAL.Delete();
        }
		
		/// <summary>
		/// Deletes all rows in a table based on a foreign key.
		/// </summary>
		/// <returns>Boolean</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWAddressId(int AddressId)
		{
			PlacementManager.DAL.LinkUserAddress_DAL oLinkUserAddress_DAL = new PlacementManager.DAL.LinkUserAddress_DAL();
			oLinkUserAddress_DAL.AddressId = AddressId;			
			return oLinkUserAddress_DAL.DeleteAllWAddressId();
		}
		[DataObjectMethodAttribute(DataObjectMethodType.Delete, true)]
		public bool DeleteAllWUserId(int UserId)
		{
			PlacementManager.DAL.LinkUserAddress_DAL oLinkUserAddress_DAL = new PlacementManager.DAL.LinkUserAddress_DAL();
			oLinkUserAddress_DAL.UserId = UserId;			
			return oLinkUserAddress_DAL.DeleteAllWUserId();
		}

	}
	
	public class LinkUserAddressComparer : IComparer<LinkUserAddress>
    {
        private string _sortColumn;
        private bool _reverse;

        public LinkUserAddressComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(LinkUserAddress a, LinkUserAddress b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "UserAddressId":
					retVal = String.Compare(a.UserAddressId.ToString(), b.UserAddressId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UserId":
					retVal = String.Compare(a.UserId.ToString(), b.UserId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "AddressId":
					retVal = String.Compare(a.AddressId.ToString(), b.AddressId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsCurrent":
					retVal = String.Compare(a.IsCurrent.ToString(), b.IsCurrent.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsPrimary":
					retVal = String.Compare(a.IsPrimary.ToString(), b.IsPrimary.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsActive":
					retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CreatedBy":
					retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateUpdated":
					retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UpdatedBy":
					retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
